package com.itheima.service.db;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.User;
import com.itheima.domain.db.UserInfo;
import com.itheima.mapper.UserInfoMapper;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    UserInfoMapper userInfoMapper;

    @Override
    public void save(UserInfo userInfo) {
        userInfoMapper.insert(userInfo);
    }

    @Override
    public void update(UserInfo userInfo) {
        userInfoMapper.updateById(userInfo);
    }

    @Override
    public UserInfo findByUserId(Long userId) {
        return userInfoMapper.selectById(userId);
    }

    @Override
    public PageBeanVo findByPage(Integer pageNum, Integer pageSize,String title) {
        //1.设置分页参数(Page对象)
        Page<UserInfo> page = new Page<>(pageNum, pageSize);

        //2.分页查询,返回Page对象
        page = userInfoMapper.selectPage(page,null);

        //3.封装PageBeanVo且返回
        return new PageBeanVo(pageNum,pageSize,page.getTotal(),page.getRecords());
    }

    @Override
    public List<UserInfo> save(QueryWrapper<UserInfo> queryWrapper) {
        return this.userInfoMapper.selectList(queryWrapper);

    }
}
